// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
    traceUser: true,
    env: 'aaa111-9gh9fp5ieac4de5d'
})

const db = cloud.database()

// 云函数入口函数
exports.main = async (event, context) => {
    const wxContext = cloud.getWXContext()
    var result = []
    var myHeartId = await db.collection('userHeart').where({
        _openid: wxContext.OPENID
    }).get()

    for (var i = 0; i < myHeartId.data.length; i++) {
        var artInfo, userInfo= {}
        await console.log(myHeartId.data[i])
        artInfo = await db.collection('postinfo').where({
            _id: myHeartId.data[i].artId
        }).get()
        userInfo = await db.collection('user').where({
            _openid: artInfo.data[0]._openid
        }).get()
        result.push({
            artInfo: artInfo.data[0],
            userInfo: userInfo.data[0]
        })
    }
    return {
        result
    }
}